package com.stack.knowyoubase.util;


import com.stack.knowyoubean.bean.PreHomeWorkModel;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.*;

/**
 * 预习作业处理工具类
 *
 * @author stack
 */
@Component
@Scope("singleton")
public class PreHomeWorkUtil {

    public List<PreHomeWorkModel> modelCreate(String content) {
        if (StringUtils.isEmpty(content)) {
            return null;
        } else {
            String[] split = content.split("\\|");
            List<PreHomeWorkModel> models = new ArrayList<>();
            for (String s : split) {
                String[] split1 = s.split(":");
                if (split1.length == 1) {
                    models.add(new PreHomeWorkModel(split1[0], 0));
                } else {
                    models.add(new PreHomeWorkModel(split1[0], Integer.parseInt(split1[1])));
                }
            }
            return models;
        }
    }

}
